View Javadoc
1 /* 2 Java Regular Expressions Plugin API 3 4 Copyright (C) 2002 Jose San Leandro Armend?riz 5 jsanleandro@yahoo.es 6 chousz@yahoo.com 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public 10 License as published by the Free Software Foundation; either 11 version 2.1 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 Thanks to ACM S.L. for distributing this library under the LGPL license. 23 Contact info: jsr000@terra.es 24 Postal Address: c/Playa de Lagoa, 1 25 Urb. Valdecaba?as 26 Boadilla del monte 27 28660 Madrid 28 Spain 29 30 This library uses some external APIs. So far I haven't released such 31 APIs as projects themselves, but you should be able 32 to download them from the web page where you got this source code. 33 34 ****************************************************************************** 35 * 36 * Filename: $RCSfile: CompilerJDKAdapter.java,v $ 37 * 38 * Author: Jose San Leandro Armend?riz 39 * 40 * Description: JDK1.4-specific regexp compiler adapter. 41 * This class makes possible the use of JDK1.4 42 * compilers inside this API. 43 * 44 * Last modified by: $Author: dev $ at $Date: 2002/09/27 08:58:37 $ 45 * 46 * File version: $Revision: 1.6 $ 47 * 48 * Project version: $Name: $ 49 * ("Name" means no concrete version has been checked out) 50 * 51 * $Id: CompilerJDKAdapter.java,v 1.6 2002/09/27 08:58:37 dev Exp $ 52 * 53 */ 54 package org.acmsl.regexpplugin.jdk14regexp; 55 56 /* 57 * Importing project-specific classes. 58 */ 59 import org.acmsl.regexpplugin.Compiler; 60 import org.acmsl.regexpplugin.jdk14regexp.MalformedPatternExceptionJDKAdapter; 61 import org.acmsl.regexpplugin.MalformedPatternException; 62 63 /* 64 * Importing some ACM classes. 65 */ 66 import org.acmsl.version.Version; 67 import org.acmsl.version.VersionFactory; 68 69 /* 70 * Importing JDK1.4 regexp classes. 71 */ 72 import java.util.regex.Pattern; 73 import java.util.regex.PatternSyntaxException; 74 75 /*** 76 * JDK1.4-specific regexp compiler adapter. This class makes 77 * possible the use of JDK1.4 compilers within this API. 78 * @author <a href="mailto:jsanleandro@yahoo.es" 79 >Jose San Leandro Armend?riz</a> 80 * @version $Revision: 1.6 $ 81 */ 82 public class CompilerJDKAdapter 83 implements Compiler 84 { 85 /*** 86 * Case sensitiveness. 87 */ 88 private boolean m__bCaseSensitive; 89 90 /*** 91 * Multiline parsing. 92 */ 93 private boolean m__bMultiline; 94 95 /*** 96 * Compiles given regular expression and creates a Pattern object to 97 * apply such rule on concrete text contents. 98 * @param regexp the regular expression to compile. 99 * @return the Pattern associated to such regular expression. 100 */ 101 public org.acmsl.regexpplugin.Pattern compile(String regexp) 102 throws MalformedPatternException 103 { 104 org.acmsl.regexpplugin.Pattern result = null; 105 106 try 107 { 108 int t_iOptions = 0; 109 110 t_iOptions |= 111 (isCaseSensitive()) 112 ? 0 113 : Pattern.CASE_INSENSITIVE; 114 115 t_iOptions |= 116 (isMultiline()) 117 ? Pattern.MULTILINE 118 : 0; 119 120 Pattern t_Pattern; 121 122 if (t_iOptions == 0) 123 { 124 t_Pattern = Pattern.compile(regexp); 125 } 126 else 127 { 128 t_Pattern = Pattern.compile(regexp, t_iOptions); 129 } 130 131 result = new PatternJDKAdapter(t_Pattern); 132 } 133 catch (PatternSyntaxException exception) 134 { 135 throw new MalformedPatternExceptionJDKAdapter(exception); 136 } 137 catch (IllegalArgumentException illegalArgumentException) 138 { 139 if (resetOptions()) 140 { 141 result = compile(regexp); 142 } 143 } 144 145 return result; 146 } 147 148 /*** 149 * Resets the compiler options. 150 * @return true if the options actually changed. 151 */ 152 private boolean resetOptions() 153 { 154 boolean result = false; 155 156 result = 157 ( (isCaseSensitive()) 158 || (isMultiline())); 159 160 setCaseSensitive(false); 161 162 setMultiline(false); 163 164 return result; 165 } 166 167 /*** 168 * Sets whether the compiler should care about case sensitiveness 169 * or not. 170 * @param caseSensitive true for differentiate upper from lower case. 171 */ 172 public void setCaseSensitive(boolean caseSensitive) 173 { 174 m__bCaseSensitive = caseSensitive; 175 } 176 177 /*** 178 * Retrieves whether the compiler should care about case sensitiveness 179 * or not. 180 * @return true if upper from lower cases are processed differently. 181 */ 182 public boolean isCaseSensitive() 183 { 184 return m__bCaseSensitive; 185 } 186 187 /*** 188 * Sets whether the compiler should care about new line delimiters 189 * or not. 190 * @param multiline false for parsing each line at a time. 191 */ 192 public void setMultiline(boolean multiline) 193 { 194 m__bMultiline = multiline; 195 } 196 197 /*** 198 * Sets whether the compiler should care about new line delimiters 199 * or not. 200 * @return false if the engine parses each line one at a time. 201 */ 202 public boolean isMultiline() 203 { 204 return m__bMultiline; 205 } 206 207 /*** 208 * Concrete version object updated everytime it's checked-in in a CVS 209 * repository. 210 */ 211 public static final Version VERSION = 212 VersionFactory.createVersion("$Revision: 1.6 $"); 213 214 /*** 215 * Retrieves the current version of this object. 216 * @return the version object with such information. 217 */ 218 public Version getVersion() 219 { 220 return VERSION; 221 } 222 223 /*** 224 * Retrieves the current version of this class. 225 * @return the object with class version information. 226 */ 227 public static Version getClassVersion() 228 { 229 return VERSION; 230 } 231 }

This page was automatically generated by Maven